<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="divTest">
        <ul id="ulTest">
        </ul>
    </div>
    <button onclick="fn()">点我</button>
    <script>
        const divTest = document.getElementById("divTest");
        const ulTest = document.getElementById("ulTest");
        let idArr = []
        for(let i = 0 ; i < 10 ; i++) {
            const li = document.createElement("li");
            const checked = document.createElement("input");
            checked.setAttribute("type", "checkbox");
            li.setAttribute("id",`${i}Id`)
            li.appendChild(checked);
            ulTest.appendChild(li)
        }
        function fn(){
            idArr = []
            const checked = document.getElementsByTagName('li')
            for(let i = 0 ; i < checked.length ; i++){
                if(checked[i].firstChild.checked){
                    checked[i].parentNode.removeChild(checked[i])
                    idArr.push(checked[i].id) 
                    i--
                }
            }
            console.log(idArr)
        }
    </script>
</body>
</html>